
package Frontera;

import Entidad.AC;
import java.awt.Color;
import java.awt.LayoutManager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.JButton;

public class ACView extends JButton implements MouseListener {

    private int estado;
    private int top;
    private AC ac;
    private static boolean mousePressed;
    private boolean derrumbe;
    
    float h,s,b=100;
    private Color test = Color.getHSBColor(h, s, b); 
    private final Color colorCero = Color.WHITE;

    public ACView(int size, int tope) {
        this.derrumbe = false;
        this.estado = 0;
        this.top = tope;        
        setSize(size, size);
        setBackground(colorCero);
        setText("0");
        setBorder(BorderFactory.createLineBorder(Color.BLACK));
        
        mousePressed = false;
        addMouseListener(this);
    }

    //Cambia de color la celda al momento de hacer click.
    private void clickSumarUno() {
        
        if(this.estado < this.top){
            this.estado = this.estado + 1;
            this.setText(estado+"");
            h=h+15;
            s=s+15;
            b=b+15;
            test= test.getHSBColor(h, s, b);
            this.setBackground(test);
        }else if(this.estado == this.top){
            this.derrumbe = !this.derrumbe;
            this.estado=0;
            setBackground(colorCero);
            setText("0");
            ac.clickDerrumbe(derrumbe);
            setVecinos();
        }
        
    }

    public void setAC(AC ac) {
        this.ac = ac;
    }

   @Override
    public void mouseClicked(MouseEvent me) {
    }

    @Override
    public void mousePressed(MouseEvent me) {
        mousePressed = true;
        clickSumarUno();
    }

    @Override
    public void mouseReleased(MouseEvent me) {
        mousePressed = false;
    }

    @Override
    public void mouseEntered(MouseEvent me) {
        if (mousePressed) {
            clickSumarUno();
        }

    }

    @Override
    public void mouseExited(MouseEvent me) {
    }

    private void setVecinos() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
